// import {mapState,mapMutations} from 'vuex'

export default {

  computed: {

    // ...mapState(['theme','userName'])

  },
  mounted() {
  // console.log(this.$utils);
    console.log(this.$DApp)
    this.init()
  },
  methods: {
    skip(i){
      this.num=i;
      console.log(i);
      let el = document.getElementById('test');
          //获取目标要锚点跳转的div
      	let st = document.getElementById(i);
          //将该div的高度赋给当前浏览的滚动条高度
      	el.scrollTop = st.offsetTop-50;

    },
    init() {
      this.$DApp.Slot.initObj().then(obj => {
         	this.Slot = obj
         	console.log(this.Slot)
      }).catch(err => {
           				 console.log(err)
      })
    },
    dialog(num) {
      if (num == 0) {
        this.$message({
          message: '请补充内容',
          type: 'warning'
        })
      } else if (num == 1) {
        this.$notify({
          title: '设置成功',
          message: '恭喜您已经设置成功',
          type: 'success'
        })
      } else if (num == 2) {
        this.$notify.error({
          title: '出现错误',
          message: '请查看控制台报错信息'
        })
      }
    },
    async test(i, data) {
      const { delBlank } = this.$utils
      // console.log(data);
      data.forEach((item, index) => {
        item.input = delBlank(item.input)
        if (data[index].input === '') {
          this.dialog(0)
        } else {

        }
      })
      if (i == 0) {
        const rarity = delBlank(data[0].input)
        let exp = delBlank(data[1].input)

        console.log(rarity, exp)

        const loading = this.$loading({
          lock: true,
          text: '请求中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        this.Slot.setRarityExp(rarity, exp).then(res => {
          const { status } = res
          if (status) {
            this.dialog(1)
            loading.close()
            this.items[i].res = status
          } else {
            loading.close()
            this.dialog(2)
          }
        }).catch(err => {
          this.items[i].res = 'false'
          console.log(err)
          loading.close()
          this.dialog(2)
        })
      } else if (i == 1) {
        const level = delBlank(data[0].input);
        const exp = delBlank(data[1].input);
        const buffer = delBlank(data[2].input);

        console.log(level,exp,buffer)
        this.Slot.setLevelConfig(level,exp,buffer).then(res => {
          const { status } = res
          if (status) {
            this.dialog(1)
            loading.close()
            this.items[i].res = status
          } else {
            loading.close()
            this.dialog(2)
          }
        }).catch(err => {
          this.items[i].res = 'false'
          console.log(err)
          loading.close()
          this.dialog(2)
        })
      } else if (i == 2) {
        const cardTypes = delBlank(data[0].input);
        const buffer = delBlank(data[1].input);

        console.log(cardTypes,buffer)
        this.Slot.addBond(cardTypes,buffer).then(res => {
          const { status } = res
          if (status) {
            this.dialog(1)
            loading.close()
            this.items[i].res = status
          } else {
            loading.close()
            this.dialog(2)
          }
        }).catch(err => {
          this.items[i].res = 'false'
          console.log(err)
          loading.close()
          this.dialog(2)
        })
      }
      else if (i == 3){
        const cardTypess = delBlank(data[0].input);
        const buffers = delBlank(data[1].input);

        console.log(cardTypess,buffers)
        this.Slot.addBonds(cardTypess,buffers).then(res => {
          const { status } = res
          if (status) {
            this.dialog(1)
            loading.close()
            this.items[i].res = status
          } else {
            loading.close()
            this.dialog(2)
          }
        }).catch(err => {
          this.items[i].res = 'false'
          console.log(err)
          loading.close()
          this.dialog(2)
        })
      }
      else if (i == 4) {
        let addr = data[0].input;
        // weights = weights.split(',');
        console.log(addr)
        if (addr === '') {
          this.dialog(0)
        } else {
          const loading = this.$loading({
            lock: true,
            text: '请求中...',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          this.Slot.setManager(addr).then(res => {
            const { status } = res
            if (status) {
              this.dialog(1)
              loading.close()
              this.items[i].res = status
            } else {
              loading.close()
              this.dialog(2)
            }
          }).catch(err => {
            this.items[i].res = 'false'
            console.log(err)
            loading.close()
            this.dialog(2)
          })
        }
        // console.log(weights)

        // console.log(weights);
      }
      else {
        const res = await this.Slot.manager()
        console.log(res)
        this.items[i].res = res;
      }
    },

    nav() {
      this.$router.push('')
    }

  },

  data() {
    return {
      num:0,
      Slot: {},
      items: [
        {
          res: '',
          tit: '1.设置稀有度和经验值的绑定',
          tips: [
            '请求合约名: Slot',
            '请求方法: setRarityExp',
            '请求方式: send'
          ],

          tableData: [
            {
              name: 'rarity',
              type: 'uint256',
              state: '稀有度',
              remark: ''
            },
            {
              name: 'exp',
              type: 'uint256',
              state: '经验值',
              remark: '卡牌燃烧后值的经验值'
            }

          ],
          test: [
            {
              place: 'rarity',
              input: ''
            },
            {
              place: 'exp',
              input: ''
            }

          ]
        },
        {
	  res: '',
	  tit: '2.设置等级配置',
	  tips: [
	    '请求合约名: Slot',
	    '请求方法: setLevelConfig',
	    '请求方式: send'
	  ],

	  tableData: [
	            {
	              name: 'level',
	              type: 'uint256',
	              state: '等级',
	              remark: ''
	            },
              {
                name: 'exp',
                type: 'uint256',
                state: '经验值',
                remark: '	当前卡牌的经验值'
              },
              {
                name: 'buffer',
                type: 'int256',
                state: '等级的加成',
                remark: ''
              },

	            ],
	  test: [
	    {
	      place: 'level',
	      input: ''
	    },
      {
        place: 'exp',
        input: ''
      },
      {
        place: 'buffer',
        input: ''
      },

	  ]
        },

        {
          res: '',
          tit: '3. 添加组合',
          tips: [
            '请求合约名: Slot',
            '请求方法: addBond',
            '请求方式: send'
          ],

          tableData: [
            {
              name: 'cardTypes',
              type: 'uint256[]',
              state: '卡槽',
              remark: '关胜，阮小五能组成水路无双'
            },
            {
              name: 'buffer',
              type: 'int256',
              state: '加成',
              remark: '这个组合的加成是多少'
            },

          ],
          test: [
            {
              place: 'cardTypes',
              input: ''
            },
            {
              place: 'buffer',
              input: ''
            },

          ]
        },
        {
          res: '',
          tit: '4. 添加多个组合',
          tips: [
            '请求合约名: Slot',
            '请求方法: addBonds',
            '请求方式: send'
          ],

          tableData: [
            {
              name: 'cardTypess',
              type: 'uint256[][]',
              state: '多个卡槽的数据',
              remark: '一次性添加多个组合'
            },
            {
              name: 'buffers',
              type: 'int256',
              state: '多个卡槽的加成',
              remark: '多个组合的加成'
            },

          ],
          test: [
            {
              place: 'cardTypess',
              input: ''
            },
            {
              place: 'buffers',
              input: ''
            },

          ]
        },
        {
          res: '',
          tit: '5.设置管理员合约地址',
          tips: [
            '请求合约名: Slot',
            '请求方法: setManager',
            '请求方式: send'
          ],

          tableData: [
        {
              name: 'addr',
              type: 'address',
              state: '输入manager合约地址',
              remark: ''
            }


          ],
          test: [


        {
              place: 'addr',
              input: ''
            }

          ]
        },
        {
          res: '',
          tit: '6.获取合约管理员地址',
          tips: [
            '请求合约名: Slot',
            '请求方法: manager',
            '请求方式: call'
          ],

          tableData: [


          ],
          test: [


          ]
        }


      ]

    }
  },

  components: {

  }

}
